<template>
  <div>
    <div class="top" v-show="sticky">
      电影
      <span @click="gocity"
        >北京
        <i class="iconfont icon-shanglajiantou"></i>
      </span>
    </div>
    <div class="chengshi" @click="gocity">
      北京
      <i class="iconfont icon-shanglajiantou"></i>
    </div>
    <Swiper></Swiper>
    <Header :class="{ showheader: showheader }"></Header>
    <router-view></router-view>
  </div>
</template>
<script>
import Header from '@/components/Header.vue'
import Swiper from '@/components/Swiper.vue'
export default {
  data() {
    return {
      sticky: false,
      showheader: false
    }
  },
  methods: {
    gocity() {
      this.$router.push('/city')
    }
  },
  components: {
    Header,
    Swiper
  },
  mounted() {
    window.addEventListener('scroll', () => {
      let t = document.documentElement.scrollTop || document.body.scrollTop
      if (t >= 220) {
        this.sticky = true
        this.showheader = true
      } else {
        this.sticky = false
        this.showheader = false
      }
    })
  }
}
</script>
<style lang='scss' scoped>
.chengshi {
  width: 50px;
  height: 25px;
  border-radius: 999em;
  text-align: center;
  line-height: 25px;
  position: absolute;
  left: 20px;
  top: 20px;
  font-size: 12px;
  color: #fff;
  z-index: 3;
  background-color: rgba($color: #000000, $alpha: 0.3);
  i {
    font-size: 10px;
  }
}
.top {
  height: 44px;
  width: 100%;
  text-align: center;
  font-size: 17px;
  color: #191a1b;
  line-height: 44px;
  position: fixed;
  z-index: 2;
  background-color: #fff;
  font-weight: 600;
  span {
    position: absolute;
    left: 20px;
    font-size: 12px;
    font-weight: 500;
    i {
      font-size: 10px;
    }
  }
}
.showheader {
  z-index: 2;
  width: 100%;
  position: fixed;
  top: 44px;
}
</style>
